﻿

using DataAccess.Enums;

namespace DataAccess.Model
{
    public class DbConfigModel
    {
        /// <summary>
        /// 数据库类型
        /// </summary>
        public DBType DbType { set; get; }

        /// <summary>
        /// 数据库名称
        /// </summary>
        public string DbName { set; get; }

        /// <summary>
        /// 数据库服务器
        /// </summary>
        public string DbServer { set; get; }

        /// <summary>
        /// 端口
        /// </summary>
        public int Port { set; get; }

        /// <summary>
        /// 用户名
        /// </summary>
        public string UId { set; get; }

        /// <summary>
        /// 密码
        /// </summary>
        public string Password { set; get; }

        /// <summary>
        /// 获取数据库连接
        /// </summary>
        /// <returns></returns>
        public string GetConnectionStr()
        {
            var result = string.Empty;
            if (DbType == DBType.MYSQL)
            {
                result = GetMysqlConnectionStr();
            }
            return result;
        }

        /// <summary>
        /// MySql连接字符串
        /// </summary>
        /// <returns></returns>
        private string GetMysqlConnectionStr()
        {
            return string.Format("server={0};user id={1}; password={2}; port={3};  pooling=false; charset=utf8",
                DbServer, UId, Password, Port);
        }
    }
}
